package cn.ysnk.generateCode;

public class EntityColumn {

	/**
	 * 是否是主键
	 */
	private boolean primaryKey=false;
	
	/**
	 * 是否生成表单
	 */
	private boolean formField=false;
	
	/**
	 * 是否是列表展示的属性
	 */
	private boolean listColumn=false;
	
	/**
	 * 字段注释，将会生成表单控件名称
	 */
	private String commont;
	/**
	 * 字段类型
	 */
	private ColumnEnum type;
	/**
	 * 字段名称
	 */
	private String columnName;

	/**
	 * 是否可空
	 */
	private boolean nullAble;
	
	private String getStr;
	
	private String setStr;
	
	/**
	 * 对应java里的基本类名称，比如String ,Integer等
	 */
	private String javaType;
	
	private String upcolumnName;
	
	/**
	 * 是否是日期
	 */
	private boolean date=false;
	
	private String formValidator = "";

	public boolean isListColumn() {
		return listColumn;
	}

	public void setListColumn(boolean listColumn) {
		this.listColumn = listColumn;
	}

	public String getCommont() {
		return commont;
	}

	public void setCommont(String commont) {
		this.commont = commont;
	}

	public EntityColumn(boolean isPrimaryKey,boolean nullAble,String commont,
			ColumnEnum type, String columnName) {
		this(isPrimaryKey, false, false,nullAble, commont, type, columnName);
	}

	public EntityColumn(boolean isPrimaryKey, boolean isFormField, boolean listColumn,boolean nullAble,String commont,
			ColumnEnum type, String columnName) {
		super();
		this.primaryKey = isPrimaryKey;
		this.formField = isFormField;
		this.listColumn = listColumn;
		this.nullAble = nullAble;
		this.commont = commont;
		this.type = type;
		this.date = type.equals(ColumnEnum.DATETIME);
		this.columnName = columnName;
		this.getStr = generateGet();
		this.setStr = generateSet();
		this.javaType = type.toString();
		this.upcolumnName = MyStringUtil.captureName(columnName);
		formValidator = type.generateFormValidator();
	}
	

	private String generateSet(){
		StringBuffer sb = new StringBuffer();
		sb.append("\n\tpublic void set")
		.append(MyStringUtil.captureName(columnName.toString()))
		.append("(").append(type.toString())
		.append(" ")
		.append(columnName)
		.append("){\n")
		.append("\t\t set(\"")
		.append(columnName)
		.append("\",")
		.append(columnName)
		.append(");\n")
		.append("\t}");
		return sb.toString();
	}
	
	private String generateGet(){
		StringBuffer sb = new StringBuffer();
		sb.append("\n\tpublic ").append(type.toString()).append(" get")
		.append(MyStringUtil.captureName(columnName.toString()))
		.append("(){\n")
		.append("\t\t ").append(type.toString()).append(" ").append(columnName)
		.append(" =  get").append(type.jfinalMethodGet()).append("(\"")
		.append(columnName)
		.append("\");\n")
		.append("\t\t return ").append(columnName).append(" == null?").append(type.generateInitValue())
		.append(":").append(columnName).append(";")
		.append("\t}");
		return sb.toString();
	}
	
	public String getFormValidator() {
		return formValidator;
	}

	public void setFormValidator(String formValidator) {
		this.formValidator = formValidator;
	}

	public boolean isPrimaryKey() {
		return primaryKey;
	}

	public void setPrimaryKey(boolean primaryKey) {
		this.primaryKey = primaryKey;
	}

	public boolean isFormField() {
		return formField;
	}

	public void setFormField(boolean formField) {
		this.formField = formField;
	}

	
	public boolean isNullAble() {
		return nullAble;
	}

	public void setNullAble(boolean nullAble) {
		this.nullAble = nullAble;
	}

	public boolean isDate() {
		return date;
	}

	public void setDate(boolean date) {
		this.date = date;
	}

	public ColumnEnum getType() {
		return type;
	}

	public void setType(ColumnEnum type) {
		this.type = type;
	}

	public String getColumnName() {
		return columnName;
	}

	public void setColumnName(String columnName) {
		this.columnName = columnName;
	}


	public String getGetStr() {
		return getStr;
	}

	public void setGetStr(String getStr) {
		this.getStr = getStr;
	}

	public String getSetStr() {
		return setStr;
	}

	public void setSetStr(String setStr) {
		this.setStr = setStr;
	}
	

	public String getJavaType() {
		return javaType;
	}

	public void setJavaType(String javaType) {
		this.javaType = javaType;
	}

	public String getUpcolumnName() {
		return upcolumnName;
	}

	public void setUpcolumnName(String upcolumnName) {
		this.upcolumnName = upcolumnName;
	}

	public static void main(String[] args) {
	}
	
	

}
